package com.wryyyyy.service.impl;

import com.wryyyyy.dto.Result;
import com.wryyyyy.entity.FoulFactory;
import com.wryyyyy.entity.FoulWaterQuality;
import com.wryyyyy.mapper.FoulFactoryMapper;
import com.wryyyyy.real.IFoulWaterDao;
import com.wryyyyy.service.IFoulFactoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wryyyyy
 * @since 2024-05-14
 */
@Service
public class FoulFactoryServiceImpl extends ServiceImpl<FoulFactoryMapper, FoulFactory> implements IFoulFactoryService {
    @Resource
    private FoulFactoryMapper foulFactoryMapper;

    @Resource
    private IFoulWaterDao foulWaterDao;

    @Override
    public Result listFactoryByCity(List<String> countryIds) {
        return Result.ok(foulFactoryMapper.getFactoryInfoByCountry(countryIds));
    }

    @Override
    public Result listFactoryByCountry(String countryId) {
        return Result.ok(foulFactoryMapper.getFactoryInfoByOneCountry(countryId));
    }

    @Override
    public Result getPassingRate(String factoryId) {
        List<String> factoryIds = new ArrayList<>();
        factoryIds.add(factoryId);
        Double passing = foulWaterDao.getPassingRate(factoryIds, false);
        return Result.ok(passing);
    }

    @Override
    public Result getAmount(String factoryId) {
        List<String> factoryIds = new ArrayList<>();
        factoryIds.add(factoryId);
        Map<LocalDateTime, Double> amount = foulWaterDao.getAmount(factoryIds);
        return Result.ok(amount);
    }

    @Override
    public Result getDosage(String factoryId) {
        List<String> factoryIds = new ArrayList<>();
        factoryIds.add(factoryId);
        Map<LocalDateTime, Double> dosage = foulWaterDao.getDosage(factoryIds);
        return Result.ok(dosage);
    }

    @Override
    public Result getContent(String factoryId) {
        List<String> factoryIds = new ArrayList<>();
        factoryIds.add(factoryId);
        FoulWaterQuality content = foulWaterDao.getContent(factoryIds);
        return Result.ok(content);
    }
}